package com.googlecode.jlogindexer.utils;

import java.util.Arrays;
import java.util.Date;

import org.apache.log4j.spi.LocationInfo;
import org.apache.log4j.spi.LoggingEvent;

import com.googlecode.jlogindexer.document.LogDocument;

public class ActiveMQMessageUtils {

	public static LogDocument convertActiveMQMessageToLogDocument(LoggingEvent logEvent){
		
		LogDocument logDocument=null;
		System.err.println("Log document is being created.......");
		logDocument = new LogDocument();
		
		logDocument.setId(logEvent.getTimeStamp());	
		logDocument.setTimestamp(new Date(logEvent.getTimeStamp()));	
		logDocument.setLevel(logEvent.getLevel().toString());	
		logDocument.setThreadName(logEvent.getThreadName());
		
		LocationInfo locationInformation = logEvent.getLocationInformation();
		
		logDocument.setClassName(locationInformation.getClassName());	
		logDocument.setFileName(locationInformation.getFileName());	
		logDocument.setMethodName(locationInformation.getMethodName());	
		logDocument.setLineNumber(locationInformation.getLineNumber());	
		if (logEvent.getRenderedMessage()!=null){
			logDocument.setOutMessage(logEvent.getRenderedMessage());	
		}
		if (logEvent.getThrowableInformation()!=null){
			logDocument.setErrorMessage(Arrays.toString(logEvent.getThrowableStrRep()));	
		}
		System.out.println("Log document creation done");
		return logDocument;
	}
}
